/**
 * 
 */
package any.tag;

import java.io.Serializable;
import java.net.URI;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "tag", "about" }))
public class TagItem implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 4518250151911864L;
    @Column(nullable = false)
    private URI               about;
    @Id @GeneratedValue
    private Long              id;
    @ManyToOne
    @JoinColumn(name="tag")
    private Tag               tag;

    public TagItem() {
        super();
    }

    public TagItem(final Tag tag, final URI about) {
        this.tag = tag;
        this.about = about;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TagItem other = (TagItem) obj;
        if (about == null) {
            if (other.about != null) {
                return false;
            }
        } else if (!about.equals(other.about)) {
            return false;
        }
        if (tag == null) {
            if (other.tag != null) {
                return false;
            }
        } else if (!tag.equals(other.tag)) {
            return false;
        }
        return true;
    }

    public URI getAbout() {
        return about;
    }

    public Long getId() {
        return id;
    }

    public Tag getTag() {
        return tag;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (about == null ? 0 : about.hashCode());
        result = prime * result + (tag == null ? 0 : tag.hashCode());
        return result;
    }
}
